import {
  IsNotEmpty,
  IsOptional,
  IsString,
  IsInt,
  IsUrl,
  Length,
} from 'class-validator';
import { Transform } from 'class-transformer';

export class CreateCommentDto {
  @IsNotEmpty({ message: '被评论文章ID不能为空' })
  @IsInt()
  articleId: number;

  @IsString()
  commentNickname: string;

  @IsOptional()
  @IsString()
  @Transform(({ value }) => (value === '' ? null : value))
  @IsUrl({ protocols: ['http', 'https'], require_protocol: true })
  commentAvatar: string | null;

  @IsString()
  @Length(0, 2000, { message: '评论长度不能超过2000' })
  comment: string;

  @IsString()
  commentEmail: string;

  @IsOptional() // 允许为 null 或 undefined
  @IsString()
  @Transform(({ value }) => (value === '' ? null : value))
  @IsUrl({ protocols: ['http', 'https'], require_protocol: true })
  website: string | null;

  @IsOptional()
  @IsInt()
  parentId: number;

  @IsOptional()
  @IsString()
  repliedNickname: string;
}
